package com.hollycrm.ahunicom.sheet.business.web;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

import com.hollycrm.ahunicom.sheet.AhConstants;
import com.hollycrm.unicom.sheet.BeanResource;
import com.hollycrm.unicom.sheet.Constants;
import com.hollycrm.unicom.sheet.business.BusinessSupportManager;
import com.hollycrm.unicom.sheet.business.web.AbstractCommitAction;
import com.hollycrm.unicom.sheet.business.web.AcceptRecordForm;
import com.hollycrm.unicom.sheet.business.web.SheetCustomerInfoForm;
import com.hollycrm.unicom.sheet.code.CodeManager;
import com.hollycrm.unicom.sheet.domain.SheetCustomerInfo;
import com.hollycrm.unicom.sheet.flowsupport.DoOperateContext;
import com.hollycrm.unicom.sheet.lightweight.ISheetCustomerInfo;

public class SheetCustomerInfoAction extends AbstractCommitAction {

    /**
     * execDefault
     *
     * @param mapping ActionMapping
     * @param actionForm ActionForm
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @throws Exception
     * @return ActionForward
     */
    public ActionForward execDefault(ActionMapping mapping,
                                     ActionForm actionForm,
                                     HttpServletRequest request,
                                     HttpServletResponse response) throws
        Exception {
        initForm(mapping, actionForm, request, response);
        
        //modify by biaocg 08-05-16
        SheetCustomerInfoForm form = (SheetCustomerInfoForm) actionForm;
        if (AhConstants.DEALSHEET_FLOWID.equals(form.getFlowID())) {
        	return mapping.findForward("formf2");
        } else {
        	return mapping.findForward("form");
        }
    }

    /**
     * initForm
     * @param mapping ActionMapping
     * @param actionForm ActionForm
     * @param request HttpServletRequest
     * @param response HttpServletResponse
     * @throws Exception
     */
    private void initForm(ActionMapping mapping,
                          ActionForm actionForm,
                          HttpServletRequest request,
                          HttpServletResponse response) throws
        Exception {
        String sheetNo = request.getParameter("customerInfo.mainSheetFlowNO");
        CodeManager codeManager = (CodeManager) getBean(BeanResource.CODE_MANAGER);
        request.setAttribute("customerLevelList",
                             codeManager.getGeneralCodeList(Constants.CUSTOMER_LEVEL));
        request.setAttribute("customerTypeList",
                             codeManager.getGeneralCodeList(Constants.CUSTOMER_TYPE));
        //modify by biaocg 08-05-16
        request.setAttribute("manufacNameList",codeManager.getGeneralCodeList(AhConstants.SHEET_MANUFAC_NAME));
        
        BusinessSupportManager bsm = (BusinessSupportManager)
            getBean(BeanResource.BUSINESSSUPPORT_MANAGER);
        ISheetCustomerInfo customerInfo = bsm.retriveSheetCustomer(sheetNo);
        SheetCustomerInfoForm form = (SheetCustomerInfoForm)actionForm;
        form.setCustomerInfo(customerInfo);//manufacNameList
        saveToken(request);
    }

    /**
     * setupCommitContext
     *
     * @param actionForm ActionForm
     * @param request HttpServletRequest
     * @param doc DoOperateContext
     * @return String
     */
    public String setupCommitContext(ActionForm actionForm,
                                     HttpServletRequest request,
                                     DoOperateContext doc) {
        SheetCustomerInfoForm form = (SheetCustomerInfoForm)actionForm;

        doc.addInputAttr("MAIN_SHEET_FLOW_NO",form.getCustomerInfo().getMainSheetFlowNO());
        doc.addInputAttr("CUSTOMER_NAME",form.getCustomerInfo().getCustomerName());
        doc.addInputAttr("TELE_NO_AREA",form.getCustomerInfo().getTeleNoArea());
        doc.addInputAttr("MOBILE_STATUS",form.getCustomerInfo().getMobileStatus());
        doc.addInputAttr("CUSTOMER_TYPE",form.getCustomerInfo().getCustomerType());
        doc.addInputAttr("CUSTOMER_LEVEL",form.getCustomerInfo().getCustomerLevel());
        doc.addInputAttr("MANUFAC_NAME",form.getCustomerInfo().getManufacName());
        
        return null;
    }

}
